package com.resou.reader.bookdetail.adapter;

import android.app.AlertDialog;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.resou.reader.api.entry.BaseComment;
import com.resou.reader.api.entry.CommentBean;
import com.resou.reader.R;
import com.resou.reader.data.local.LitePalHelper;
import com.resou.reader.mine.IView.UserInstance;
import com.resou.reader.utils.DateUtils;
import com.resou.reader.utils.PreferenceUtil;
import com.ms.square.android.expandabletextview.ExpandableTextView;
import com.resou.reader.view.StarRatingBar;

import java.util.List;

/**
 * Author: 萤火虫
 * E-mail:  Allensuns@163.com
 * Description:
 * CreateTime: 2019-04 -10
 **/
public class CommentListAdapter extends BaseQuickAdapter<BaseComment.DataBean, BaseViewHolder> {
    public CommentListAdapter(int layoutResId, @Nullable List<BaseComment.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BaseComment.DataBean item) {
        helper.addOnClickListener(R.id.llComment)
                .addOnClickListener(R.id.llPraise)
                .addOnClickListener(R.id.llCommentOnclickLister)
                .setText(R.id.expandable_text, item.getContent() + "");
        RequestOptions options = new RequestOptions();
        options.format(DecodeFormat.PREFER_RGB_565);
        Glide.with(mContext).load(item.getHead_pic() == null ? "" : item.getHead_pic()).apply(options).into((ImageView) helper.getView(R.id.comment_head));
        StarRatingBar starRatingBar = helper.getView(R.id.starRatingBar);
        starRatingBar.setIsClickable(false);
        starRatingBar.setStarMark(Float.valueOf(item.getLevel()));
        helper.setText(R.id.tvUserName, item.getNickName())
                .setText(R.id.tvTime, DateUtils.getTheDayFromNow(item.getCreate_date()));
        TextView tvTime = helper.getView(R.id.tvTime);
        if (tvTime.getText().toString().equals("刚刚")) {
            helper.setTextColor(R.id.tvTime, mContext.getResources().getColor(R.color.theme_color));
        } else {
            helper.setTextColor(R.id.tvTime, mContext.getResources().getColor(R.color.color757575));
        }
        helper.setText(R.id.tvCommentNum,
                item.getReviewCount() == 0 ? "回复" :
                        item.getReviewCount() + "");
        if (PreferenceUtil.getInstance(mContext).getlocalCommentPariseState(item.getId() + "")) {
            helper.setImageResource(R.id.ivLike, R.mipmap.ic_commentliked);
        } else {
            helper.setImageResource(R.id.ivLike, R.mipmap.ic_commentlike);
        }
        helper.setText(R.id.tvLikeNum, item.getPraisenum() == 0 ? "点赞" : item.getPraisenum() + "");


    }
}
